//
//  BQsetCell.m
//  BeeQuick
//
//  Created by 万伶童 on 16/11/21.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQsetCell.h"
@interface BQsetCell()
@property(assign,nonatomic)BOOL isSwitchBtn;

@end
@implementation BQsetCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    UILabel * nightLabel = [[UILabel alloc]init];
    nightLabel.text = @"夜间模式";
    UISwitch * switchBtn = [[UISwitch alloc]init];
    switchBtn.on = NO;
    BOOL isON = [switchBtn isOn];
    _isSwitchBtn = isON;
    self.isSwitchBtn = switchBtn;
    [switchBtn addTarget:self action:@selector(nightTime:) forControlEvents:UIControlEventValueChanged];
    

    
    //MARK:添加
    [self.contentView addSubview:nightLabel];
    [self.contentView  addSubview:switchBtn];


    
    //MARK:设置约束
    [nightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.centerY.equalTo(self.contentView);
        make.left.offset(14);
    }];
    [switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.offset(-8);
    }];
    
}
- (void)nightTime:(id)sender{
    
    UISwitch * switchBtn = (UISwitch*)sender;
    BOOL isON = [switchBtn isOn];
//    NSLog(@"当前值是：%@", isON ? @"YES" : @"NO");
    //MARK: 判断当前值是否一样
    if (isON == _isSwitchBtn)
    {
        _isSwitchBtn = isON;
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:self];
        
    }
    else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"deful" object:self];
    }
    
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
